import json

from base.base import Base
from dao.mysqlhelper import MySQLHelper

# 197或207上批量增加标准属性，需要先查出re数据，因为数据库端口没放开

# mysql=MySQLHelper()
# # SQL 查询语句
# sql = """
# SELECT
#   	mc.catalog_id,
#   	mv.model_vid
# FROM
# 	t_fusion_model_catalog mc
# 	LEFT JOIN t_fusion_model fm ON mc.catalog_id = fm.catalog_id
# 	LEFT JOIN t_fusion_model_version mv ON fm.model_id = mv.model_id
# 	LEFT JOIN t_fusion_model_attribute ma ON mv.model_vid = ma.model_vid
# WHERE
# 	( mc.namepath LIKE '空间资源%' OR mc.namepath LIKE '感知资源%' OR mc.namepath LIKE '服务资源%' )
# 	AND mc.del_flag = 0
# 	AND fm.del_flag = 0
# --  	AND ma.del_flag != 1
# 	AND mc.node_level != 1
# GROUP BY
# 	ma.model_vid
# HAVING
# 	count(*)=1
# """
# re=mysql.select(sql)
# print(re)
# print(len(re))
re=(('1869303267629105153', '1872171905759440897'), ('1849028694694281217', '1872173013961666561'), ('1849028728068358145', '1872178314416877570'), ('1859846857820356610', '1872180385874571266'), ('1859848923657682945', '1872180503017287682'), ('1859854837286584321', '1872180557505490945'), ('1859854878126522369', '1872180610647322625'), ('1860298335236276225', '1872180645984333825'), ('1859475068854423553', '1872180714431180802'), ('185144188155', '1872181106833485825'), ('186115125803', '1872181720980254722'), ('184884049397', '1872184007932899330'), ('1862040068148051969', '1872184672906244097'), ('180170344227', '1872485411842478082'), ('180354980671', '1872486048978227201'), ('180568366683', '1872486049603178497'), ('181182827997', '1872486050068746241'), ('181669243023', '1872486050953744386'), ('182082827466', '1872486051331231745'), ('182500912258', '1872486051742273537'), ('182790329692', '1872486052371419138'), ('182847496138', '1872486052669214722'), ('183111592692', '1872486053097033730'), ('183374940909', '1872486053461938177'), ('183562625630', '1872486053801676802'), ('183636676574', '1872486054145609730'), ('183724039148', '1872486054489542657'), ('183766105900', '1872486054799921154'), ('183844791672', '1872486055030607873'), ('183868417356', '1872486055756222465'), ('183984951606', '1872486056184041474'), ('1843450284247810049', '1872486056465059841'), ('1843451073167032322', '1872486056758661121'), ('184383314236', '1872486057052262402'), ('184794813788', '1872486057522024450'), ('1848679394336423937', '1872486057824014337'), ('1849025385203875841', '1872486058394439681'), ('1849025828130766849', '1872486058801287170'), ('1849030271270240257', '1872486059707256834'), ('1849030609561829377', '1872486060000858114'), ('1849030841699778562', '1872486060265099266'), ('1849031159770628098', '1872486060554506242'), ('1849031547160739842', '1872486060822941698'), ('1849031616165429249', '1872486061468864513'), ('1849031731026444289', '1872486061758271489'), ('1849032419685023745', '1872486062064455682'), ('184951098794', '1872486062416777218'), ('185398358003', '1872486063100448770'), ('185546877690', '1872486063389855745'), ('185572692370', '1872486063851229186'), ('1855726923701305', '1872486064119664642'), ('1855726923701805', '1872486064551677953'), ('1855726923702105', '1872486064815919105'), ('1855726923702205', '1872486065805774850'), ('1855726923702305', '1872486066095181826'), ('1855726923702405', '1872486066397171713'), ('1855726923702505', '1872486066858545154'), ('1855726923702605', '1872486067156340737'), ('185680578970', '1872486067462524930'), ('185827668180', '1872486069232521218'), ('185938150331', '1872486069773586433'), ('1859430696528097282', '1872486070243348481'), ('1859430755500011521', '1872486070532755458'), ('1859431029866213377', '1872486070822162433'), ('186216153576', '1872486073925947393'), ('186310504173', '1872486074198577153'), ('186440321855', '1872486075033243649'), ('1866402279184302081', '1872486075301679106'), ('1867045450901782530', '1872486075763052545'), ('186725874835', '1872486075981156354'), ('186735287707', '1872486076358643714'), ('186917022487', '1872486076673216513'), ('1869281237227700225', '1872486076924874753'), ('1869302877915348994', '1872486077243641857'), ('186946600945', '1872486077981839361'), ('1869955055613018114', '1872486078279634946'), ('1870293496917819394', '1872486078522904577'), ('187166701890', '1872486078921363457'), ('187547523339', '1872486080154488833'), ('187786840999', '1872486080506810369'), ('188339423383', '1872486080871714817'), ('188505260843', '1872486081127567362'), ('188566722722', '1872486081396002818'), ('188575002973', '1872486081609912322'), ('188606845149', '1872486081869959170'), ('188767996086', '1872486082306166786'), ('188800933224', '1872486082771734530'), ('188982297116', '1872486083027587074'), ('189454172347', '1872486083304411138'), ('189535919631', '1872486083556069378'))
base=Base()
if len(re)>0:
    param_type='application/json'
    headers={
        'appcode':'FUSION',
        'authorization':'Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1aWQiOiIxODM4NTE3NDc2ODU5MTcwODE3Iiwic3ViIjoienpoIiwiYXVkIjoidGVuYW50IiwidW5hbWUiOiJ6emgiLCJhcHBJZCI6Ijk2OWYyYjBjMzY2YTQ2NWE5ZmU4ZGZmMDEyZDE3MjFhIiwiaXNzIjoiaWRhYXMiLCJ0ZW5hbnRJZCI6ImRlZmF1bHRUZW5hbnRJZCIsInV0eXBlIjoidXNlciIsInJuZCI6IjA1eG95dGw2IiwiZXhwIjoxNzM5NTEzOTU5LCJpYXQiOjE3Mzk0Mjc1NTl9.O-YB4Yg3HQgoreCv-eLhCvSu2VC4U8VqBs-9w7EdJHU'
    }

    for catalog_id in re:
        data={
            "catalogId": catalog_id[0],
            "modelAttributeList": [
                {
                    "remark": "归属空间实体名称",
                    "createTime": "2025-02-14 08:18:08",
                    "createBy": "zzh",
                    "updateTime": "2025-02-14 08:18:08",
                    "updateBy": "zzh",
                    "delFlag": False,
                    "tenantId": "defaultTenantId",
                    "createByName": None,
                    "updateByName": None,
                    "attributeName": "归属空间实体名称",
                    "attributeCode": "belong_space_name",
                    "dataType": "String",
                    "attributeUnit": None,
                    "attributeType": None,
                    "attributeScope": "100",
                    "state": True,
                    "key": "4293c3bcc2ce4a6c9db7fb5cf5730ec8"
                },
                {
                    "remark": "归属单位名称",
                    "createTime": "2025-02-14 08:17:48",
                    "createBy": "zzh",
                    "updateTime": "2025-02-14 08:17:48",
                    "updateBy": "zzh",
                    "delFlag": False,
                    "tenantId": "defaultTenantId",
                    "createByName": None,
                    "updateByName": None,
                    "attributeName": "归属单位名称",
                    "attributeCode": "belong_unit_name",
                    "dataType": "String",
                    "attributeUnit": None,
                    "attributeType": None,
                    "attributeScope": "100",
                    "state": True,
                    "key": "2c048bd19da0438689402208859a605a"
                },
                {
                    "remark": "管理单位名称",
                    "createTime": "2025-02-14 08:17:24",
                    "createBy": "zzh",
                    "updateTime": "2025-02-14 08:17:24",
                    "updateBy": "zzh",
                    "delFlag": False,
                    "tenantId": "defaultTenantId",
                    "createByName": None,
                    "updateByName": None,
                    "attributeName": "管理单位名称",
                    "attributeCode": "manage_unit_name",
                    "dataType": "String",
                    "attributeUnit": None,
                    "attributeType": None,
                    "attributeScope": "100",
                    "state": True,
                    "key": "98c99469b6c140138217dbed241ee0cb"
                }
            ]
        }
        url='http://117.187.242.207:8082/idaas/idaas-gateway/talkweb-fusion-server/modelAttribute/saveAttribute'
        res=json.loads(base.send_post(url,param_type,headers=headers,data=data))['msg']
        print(f"{catalog_id[0]} 结果为：{res}")